<?php
class APF_Http_Client_Curl {

    private $curl;
    /**
     * @return APF_Http_Client_Curl
     */
    public function __construct() {
        $this->curl = curl_init();
        $this->init();
    }

    public function init () {
        $this->set_attribute(CURLOPT_HTTPHEADER, array("Content-type:text/xml; charset=utf-8"));
        $this->set_attribute(CURLOPT_RETURNTRANSFER, 1);
        $this->set_attribute(CURLOPT_CONNECTTIMEOUT, 10);
        $this->set_attribute(CURLOPT_TIMEOUT, 10);
    }

    public function set_url ($url) {
        curl_setopt($this->curl,CURLOPT_URL,$url);
    }

    public function set_attribute ($name,$value) {
        curl_setopt($this->curl,$name,$value);
    }
    
    public function set_timeout($time){
    	$this->set_attribute(CURLOPT_TIMEOUT,$time);
    }

    /**
     * @return boolean
     */
    public function execute() {
        $this->response_text = curl_exec($this->curl);
        $this->curl_info = curl_getinfo($this->curl);
        if ($this->curl_info['http_code'] == 200) {
            return true;
        } else {
            return false;
        }
    }

    private $response_text;
    private $curl_info;

    public function get_response_text () {
        return $this->response_text;
    }

    public function get_curl_info () {
        return $this->curl_info;
    }

    public function __destruct() {
        curl_close($this->curl);
    }
}
?>